package top.kpromise.common.base;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.domain.Page;

import java.util.List;

@Getter
@Setter
@ToString
public class PageResult<T> extends Result<List<T>> {

    public PageResult<T> setResult(Page<T> result) {
        setData(result.getContent());
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPageNo(result.getPageable().getPageNumber() + 1);
        pageInfo.setPageSize(result.getPageable().getPageSize());
        pageInfo.setTotal(result.getTotalElements());
        setPageInfo(pageInfo);
        return this;
    }
}
